﻿using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

namespace Dan{
    public class ParticleGUI : CustomShaderGUI
    {
        
        protected override void ShowGUI()
        {
            ShowMain();
            ShowUVFlow();
            ShowMask();
            ShowDistort();
            ShowDissolve();
            ShowSoftParticle();
            ShowRenderMode();
        }

        void ShowMain()
        {
            ShowPropertys("_TintColor");
            ShowPropertys("_MainTex");
        }
        
        void ShowUVFlow(){
            ShowPropertys("_UseUVFlow");
            var property = ShaderGUI.FindProperty("_UseUVFlow", properties);
            if (property.floatValue > 0.5) {
                ShowPropertys("_FlowSpeedX");
                ShowPropertys("_FlowSpeedY");
            }

        }
        
        void ShowMask(){
            ShowBlock("_MaskTex","USE_UV_MASK",()=>{
                ShowPropertys("_MaskTex");
            });
        }
        
        void ShowDistort(){
            ShowBlock("_DistortTex","USE_DISTORT",()=>{
                ShowPropertys("_DistortTex");
                ShowPropertys("_DistrotStrength");
                ShowPropertys("_DistortRotateSpeed");
            });
        } 
        void ShowDissolve(){
            ShowBlock("_DissolveTex","USE_DISSOLVE",()=>{
                ShowPropertys("_DissolveTex");
                ShowPropertys("_DissolveProgress");
                ShowPropertys("_DissolveColor");
                ShowPropertys("_DissolveRange");
            });
        }
        
        void ShowSoftParticle(){
            var _UseSoftParticle = ShaderGUI.FindProperty("_UseSoftParticle", properties);
            editor.ShaderProperty(_UseSoftParticle, _UseSoftParticle.displayName);
            if (_UseSoftParticle.floatValue > 0.5f) {
                ShowPropertys("_InvFade");
            }
        }
        
        void ShowRenderMode(){
            ShowPropertys("_CullMode");
            var _BlendMode = ShaderGUI.FindProperty("_BlendMode", properties);
            editor.ShaderProperty(_BlendMode, _BlendMode.displayName);

            var blendMode = (EBlendMode)Mathf.RoundToInt(_BlendMode.floatValue);
            SetupMaterialWithBlendMode(target,blendMode,lastBlendMode != -1 && lastBlendMode != (int)blendMode);
            lastBlendMode = (int)blendMode;
            //editor.RenderQueueField();
        }
        
        
        
        
        
        
        
        
        
        
    }

}
